

/*****************/
/*                                                                                
/* Create Table1 */
/*                                                                                
/*****************/



libname raw 'G:\Data\Rawdata\707677';

libname common 'G:\Data\Workdata\707677\Common\01Data\01SAS';





/*******************/
/* Load our sample */
/*******************/


data automat;

set common.list;

run;




/******************************/
/* Create variables for table */
/******************************/



data automat;

set automat;

age=input(alder,3.0);

run;




data automat;

set automat;


employed_pstill=0; 

unemployed_pstill=0; 

out_of_lf_pstill=0;


pstill_num=INPUT(PSTILL,2.0);


if pstill_num=. then employed_pstill=.; 

if pstill_num=. then unemployed_pstill=.;

if pstill_num=. then out_of_lf_pstill=.;


if (pstill_num<38 and pstill_num~=.) or pstill_num in (71,72,73,74,75,76,77) then employed_pstill=1;

if pstill_num=40 then unemployed_pstill=1;

if (pstill_num>40 and pstill_num<58) or (pstill_num in (90,91,92,93,94,95,96,97,98)) then out_of_lf_pstill=1;


run;




/* Divorced and widowed */


data automat;

set automat;

divorced=.;

widowed=.;

if civst~='' then divorced=0;

if civst~='' then widowed=0;

if civst='F' then divorced=1;

if civst='E' then widowed=1;

run;




/* Self-employed */


data automat;

set automat;

self=0;

if (netovskud~=. AND netovskud~=0) OR (netovskud_gl~=. AND netovskud_gl~=0) OR (netovskud_13~=. AND netovskud_13~=0) then self=1;

run;





/**********************/
/* Compute statistics */
/**********************/



proc sort data=automat;

by granted;

run;



proc summary data=automat;

class granted;

var age male home legmarried schooling ANTBOERNF ANTPERSF DISPON_NY LOENMV ERHVERVSINDK_13 FORMUE AKTIV PASSIV KOEJD employed_pstill unemployed_pstill out_of_lf_pstill;

output out= tautomat

sum(male home legmarried)=sum_male sum_home sum_legmarried

sum(employed_pstill unemployed_pstill out_of_lf_pstill)=sum_employed_pstill sum_unemployed_pstill sum_out_of_lf_pstill

mean(age schooling ANTBOERNF ANTPERSF)=mean_age mean_schooling mean_children mean_people

mean(DISPON_NY LOENMV ERHVERVSINDK_13 FORMUE AKTIV PASSIV KOEJD)=mean_DISPON_NY mean_LOENMV mean_ERHVERVSINDK_13 mean_FORMUE mean_AKTIV mean_PASSIV mean_KOEJD 

std(age schooling ANTBOERNF ANTPERSF)=std_age std_schooling std_children std_people

std(DISPON_NY LOENMV ERHVERVSINDK_13 FORMUE AKTIV PASSIV KOEJD)=std_DISPON_NY std_LOENMV std_ERHVERVSINDK_13 std_FORMUE std_AKTIV std_PASSIV std_KOEJD; 

run; 




/* Round numbers */


data tautomat;

set tautomat;

mean_DISPON_NY=ROUND(mean_DISPON_NY/1000,1); 

mean_LOENMV=ROUND(mean_LOENMV/1000,1); 

mean_ERHVERVSINDK_13=ROUND(mean_ERHVERVSINDK_13/1000,1);

mean_FORMUE=ROUND(mean_FORMUE/1000,1); 

mean_AKTIV=ROUND(mean_AKTIV/1000,1); 

mean_PASSIV=ROUND(mean_PASSIV/1000,1); 

mean_KOEJD=ROUND(mean_KOEJD/1000,1); 

std_DISPON_NY=ROUND(std_DISPON_NY/1000,1); 

std_LOENMV=ROUND(std_LOENMV/1000,1); 

std_ERHVERVSINDK_13=ROUND(std_ERHVERVSINDK_13/1000,1);

std_FORMUE=ROUND(std_FORMUE/1000,1); 

std_AKTIV=ROUND(std_AKTIV/1000,1); 

std_PASSIV=ROUND(std_PASSIV/1000,1); 

std_KOEJD=ROUND(std_KOEJD/1000,1); 

run;





data atabell;

length description N male_mean home_mean age_mean age_std legmarried_mean 

schooling_mean children_mean people_mean

DISPON_NY_mean LOENMV_mean ERHVERVSINDK_13_mean FORMUE_mean AKTIV_mean PASSIV_mean KOEJD_mean 

employed_pstill_mean unemployed_pstill_mean out_of_lf_pstill_mean



$50;

set tautomat;

N=strip(put(_freq_,8.));


if granted=. then description="Applied";

if granted=1 then description="Granted";

if granted=0 then description="Denied";


male_mean=strip(put(100*sum_male/N,8.1));

home_mean=strip(put(100*sum_home/N,8.1));

legmarried_mean=strip(put(100*sum_legmarried/N,8.1));


employed_pstill_mean=strip(put(100*sum_employed_pstill/N,8.1)); 

unemployed_pstill_mean=strip(put(100*sum_unemployed_pstill/N,8.1)); 

out_of_lf_pstill_mean=strip(put(100*sum_out_of_lf_pstill/N,8.1));


age_mean=strip(put(mean_age,8.1));

age_std='(' || strip(put(std_age,8.1)) || ')';


schooling_mean=strip(put(mean_schooling,8.1)); 

schooling_std='(' || strip(put(std_schooling,8.1)) || ')';



children_mean=strip(put(mean_children,8.1)); 

children_std='(' || strip(put(std_children,8.1)) || ')';



people_mean=strip(put(mean_people,8.1));

people_std='(' || strip(put(std_people,8.1)) || ')';



DISPON_NY_mean=strip(put(mean_DISPON_NY,8.0)); 

DISPON_NY_std='(' || strip(put(std_DISPON_NY,8.0)) || ')';


LOENMV_mean=strip(put(mean_LOENMV,8.0)); 

LOENMV_std='(' || strip(put(std_LOENMV,8.0)) || ')';


ERHVERVSINDK_13_mean=strip(put(mean_ERHVERVSINDK_13,8.0)); 

ERHVERVSINDK_13_std='(' || strip(put(std_ERHVERVSINDK_13,8.0)) || ')';


FORMUE_mean=strip(put(mean_FORMUE,8.0)); 

FORMUE_std='(' || strip(put(std_FORMUE,8.0)) || ')';


AKTIV_mean=strip(put(mean_AKTIV,8.0)); 

AKTIV_std='(' || strip(put(std_AKTIV,8.0)) || ')';


PASSIV_mean=strip(put(mean_PASSIV,8.0)); 

PASSIV_std='(' || strip(put(std_PASSIV,8.0)) || ')';


KOEJD_mean=strip(put(mean_KOEJD,8.0)); 

KOEJD_std='(' || strip(put(std_KOEJD,8.0)) || ')';


run;




proc transpose data=atabell out=sluttabell;

var N male_mean age_mean age_std home_mean legmarried_mean schooling_mean schooling_std children_mean children_std people_mean people_std

DISPON_NY_mean DISPON_NY_std LOENMV_mean LOENMV_std ERHVERVSINDK_13_mean ERHVERVSINDK_13_std 

FORMUE_mean FORMUE_std AKTIV_mean AKTIV_std PASSIV_mean PASSIV_std employed_pstill_mean unemployed_pstill_mean out_of_lf_pstill_mean;

id description;

run;



/* Snyggar till tabellen */


proc datasets library=work nolist;

modify sluttabell;

attrib _all_ label='';

quit;



data sluttabell;

set sluttabell;

rename _name_=variable;

run;



data sluttabell;

retain variable applied granted denied;

set sluttabell;

run;



data sluttabell;

set sluttabell;

length newvar $50;

if variable="N" then newvar="N";

if variable="male_mean" then newvar="Fraction men";

if variable="age_mean" then newvar="Mean age";


if variable="home_mean" then newvar="Fraction real-estate owners";

if variable="legmarried_mean" then newvar="Fraction legally married";


if variable="schooling_mean" then newvar="Mean years schooling";

if variable="people_mean" then newvar="Mean number persons";

if variable="children_mean" then newvar="Mean number children";

if variable="DISPON_NY_mean" then newvar="Mean disposable income";

if variable="LOENMV_mean" then newvar="Mean earnings";

if variable="ERHVERVSINDK_13_mean" then newvar="Mean earned income";


if variable="FORMUE_mean" then newvar="Mean wealth";

if variable="AKTIV_mean" then newvar="Mean assets";

if variable="PASSIV_mean" then newvar="Mean debt";

if variable="KOEJD_mean" then newvar="Mean real estate wealth";



if variable="employed_pstill_mean" then newvar="Fraction employed";

if variable="unemployed_pstill_mean" then newvar="Fraction unemployed ";

if variable="out_of_lf_pstill_mean" then newvar="Fraction out of labor force";


run;





data obs;

set sluttabell;

if variable='N';

run;



data age;

set sluttabell;

if variable='age_mean' or variable='age_std';

run;



data demo;

set sluttabell;

if variable='legmarried_mean' or variable='children_mean' or variable='children_std' or variable='people_mean' or variable='people_std'; 

run;



data school;

set sluttabell;

if variable='schooling_mean' or variable='schooling_std';

run;



data income;

set sluttabell;

if variable='DISPON_NY_mean' or variable='DISPON_NY_std' or variable='LOENMV_mean' or variable='LOENMV_std' 

or variable='ERHVERVSINDK_13_mean' or variable='ERHVERVSINDK_13_std' 

or variable="employed_pstill_mean" or variable="unemployed_pstill_mean" or variable="out_of_lf_pstill_mean"; 

run;



data wealth;

set sluttabell;

if variable='FORMUE_mean' or

variable='FORMUE_std' or

variable='AKTIV_mean' or

variable='AKTIV_std' or

variable='PASSIV_mean' or

variable='PASSIV_std' or

variable='KOEJD_mean' or

variable='KOEJD_std';

run;



data men;

set sluttabell;

if variable='male_mean';

run;



data home;

set sluttabell;

if variable='home_mean';

run;




data sluttabell;

set age men demo school home income wealth obs;

run;



proc datasets library=work nolist;

delete age men demo school home income wealth obs;

quit;



data sluttabell;

retain newvar;

set sluttabell;

drop variable;

run;





proc export data=sluttabell outfile='G:\Data\Workdata\707677\Common\03Output\03Tables\table1.xls' dbms=excel5 replace;

run;






proc datasets library=work nolist kill;

quit;









